﻿package {
	import com.et.ball.view.GameLayer;
	import com.et.ball.view.MenuLayer;
	import com.et.ball.view.ResultLayer;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.text.*;
	
	[SWF(width="480",height="720",frameRate="30",backgroundColor="0xffffff")]  //width="1000",height="600",
	public class Game extends Sprite 
	{
		private var menulayer:MenuLayer;
		private var gamelayer:GameLayer;
		private var resultlayer:ResultLayer;
		
		public function Game() {
			if (stage) {
				init();
			} else {
				this.addEventListener(Event.ADDED_TO_STAGE, init); 
			}
		}
		
		private function onResize(e:Event):void 
		{
			 
		}
		 
		private function init():void {
			stage.scaleMode = "noScale";  
			stage.align ="TL";
			stage.tabChildren = false;
			stage.addEventListener(Event.RESIZE , onResize);
			
			menulayer=new MenuLayer(this);
			menulayer.addEventListener("play",playHandler)
			addChild(menulayer);
		}

		//点击Play选择按钮；
		private function playHandler(event:Event):void {
 			if(menulayer && menulayer.parent){
				this.removeChild(menulayer);
				menulayer=null;
			}
		 
			gamelayer=new GameLayer(this);
			gamelayer.addEventListener("replay",resetHandler);
			addChild(gamelayer);
			 
		}
		
		//点击Play选择按钮；
		private function resetHandler(event:Event):void {
			if(gamelayer && gamelayer.parent){
				this.removeChild(gamelayer);
				gamelayer=null;
			}
			menulayer=new MenuLayer(this);
			menulayer.addEventListener("play",playHandler)
			addChild(menulayer);
		}
   
	}
}